package xcmg.device.service.warehouse.allot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import xcmg.device.dao.entity.delivery.DeliveryReceiptMaterialDO;
import xcmg.device.dao.entity.warehouse.allot.RegionAllotCrmDO;
import xcmg.device.dao.entity.warehouse.allot.RegionAllotDO;
import xcmg.device.dao.entity.warehouse.allot.RegionAllotDetailDO;
import xcmg.device.dao.mapper.delivery.DeliveryReceiptLinkMapper;
import xcmg.device.dao.mapper.delivery.DeliveryReceiptMaterialMapper;
import xcmg.device.dao.mapper.warehouse.RegionAllotDetailMapper;
import xcmg.device.dao.mapper.warehouse.RegionAllotMapper;
import xcmg.device.infra.ConstantInfo;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.JsonUtil;
import xcmg.device.infra.StringUtil;
import xcmg.device.service.delivery.DeliveryReceiptMaterialService;
import xcmg.device.service.vo.warehouse.allot.RegionAllotDetailVO;
import xcmg.device.service.vo.warehouse.allot.RegionAllotVO;
import xcmg.device.util.CompanyUtil;
import yb.ecp.fast.feign.FastGenClient;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.util.ListUtil;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RegionAllotDetailService {

    @Autowired
    private RegionAllotDetailMapper regionAllotDetailMapper;

    @Autowired
    private RegionAllotMapper regionAllotMapper;

    @Autowired
    private FastGenClient fastGenClient;

    @Autowired
    private DeliveryReceiptLinkMapper deliveryReceiptLinkMapper;

    @Autowired
    private DeliveryReceiptMaterialService deliveryReceiptMaterialService;

    @Autowired
    private DeliveryReceiptMaterialMapper deliveryReceiptMaterialMapper;

    @Autowired
    private CompanyUtil companyUtil;

    private static final Logger logger = LoggerFactory.getLogger(RegionAllotDetailService.class);

    /**
     * @Author: WangKe
     * @Description: 新增区域调拨详情记录
     * @Date: 2018/2/11 0011
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean add(RegionAllotDetailVO regionAllotDetailVO) throws Exception{
        ActionResult<String> textResult = fastGenClient.textGuid();
        if (textResult.getCode() != ErrorCode.Success.getCode())
        {
            return false;
        }
        regionAllotDetailVO.setId(textResult.getValue());
        regionAllotDetailVO.setCreateDate(new Date());

        RegionAllotDetailDO detailDO = new RegionAllotDetailDO();
        BeanUtils.copyProperties(regionAllotDetailVO, detailDO);
        detailDO.setInAmount(BigDecimal.ZERO);
        detailDO.setOutAmount(BigDecimal.ZERO);
        detailDO.setInState(0);
        detailDO.setOutState(0);
        return regionAllotDetailMapper.insert(detailDO)>0;
    }

    /**
     * @Author: WangKe
     * @Description: 在零件扫描入库时更新区域调拨主表和详情表相关记录
     * @Date: 2018/2/12 0012
     */
    public boolean updateByInbound(String allotOrder, String materialNo, BigDecimal realAmount,
                                   Integer singelState, Integer totalState, String orgId){
        RegionAllotDetailVO detailVO = new RegionAllotDetailVO();
        detailVO.setAllotOrder(allotOrder);
        detailVO.setMaterialNo(materialNo);
        detailVO.setOrgId(orgId);
        List<RegionAllotDetailDO> list = regionAllotDetailMapper.list(detailVO);
        if(ListUtil.isNullOrEmpty(list)){
            return false;
        }
        RegionAllotDetailDO detailDO = list.get(0);
        detailDO.setInAmount(realAmount);
        detailDO.setInState(singelState);
        boolean success = regionAllotDetailMapper.updateByPrimaryKeySelective(detailDO)>0;
        if(success) {
            RegionAllotVO inboundVO = new RegionAllotVO();
            inboundVO.setAllotOrder(allotOrder);
            inboundVO.setOrgId(orgId);
            List<RegionAllotDO> inboundList = regionAllotMapper.list(inboundVO);
            if (ListUtil.isNullOrEmpty(inboundList)) {
                return false;
            }
            RegionAllotDO inboundDO = inboundList.get(0);
            getInState(allotOrder, totalState, orgId, inboundDO);

            //调用crm接口，同步crm状态
//            if (companyUtil.isTJ(orgId)) {  //塔机用户才同步crm
//                Map resultMap = syncCrmByInbound(allotOrder, materialNo, inboundDO);
//
//                boolean isSuccess = true;
//
//                //syncCrmFlag为null,为未同步
//                if (!StringUtil.isNotEmpty(inboundDO.getSyncCrmFlag())){
//                    inboundDO.setSyncCrmFlag("0");
//                }
//
//                //同步失败需要回写
//                if (resultMap.get("Flag") != null && resultMap.get("Flag").equals(false)){
//                    String msg = inboundDO.getSyncCrmMsg() == null ? "" : inboundDO.getSyncCrmMsg();
//                    msg += resultMap.get("Msg").toString() + ";";
//                    inboundDO.setSyncCrmFlag("2");
//                    inboundDO.setSyncCrmMsg(msg);
//                    isSuccess = false;
//                }
//
//                //本次同步成功，并且之前没有失败记录则回写成功
//                if (isSuccess && !inboundDO.getSyncCrmFlag().equals("2")){
//                    inboundDO.setSyncCrmFlag("1");
//                    inboundDO.setSyncCrmMsg("操作成功");
//                }
//            }

            success = regionAllotMapper.updateByPrimaryKeySelective(inboundDO) > 0;
        }

        return success;
    }

    private void getInState(String allotOrder, Integer totalState, String orgId, RegionAllotDO inboundDO) {
        RegionAllotDetailVO regionAllotDetailVO = new RegionAllotDetailVO();
        regionAllotDetailVO.setAllotOrder(allotOrder);
        regionAllotDetailVO.setOrgId(orgId);
        boolean state = false;
        List<RegionAllotDetailDO> regionAllotDetailDOList = regionAllotDetailMapper.list(regionAllotDetailVO);
        for (RegionAllotDetailDO regionAllotDetailDO: regionAllotDetailDOList) {// 校验调拨详情中所有的入库状态是否全部==2
            Integer inState =  regionAllotDetailDO.getInState();
            if (2 != inState){
                state = true;
                break;
            }
        }
        inboundDO.setInState(totalState);
        if (!state){
            inboundDO.setInState(2);
        }
    }

    /**
     * @Author: WangKe
     * @Description: 在扫描出库时更新区域调拨单状态
     * @Date: 2018/2/12 0012
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean updateByOutbound(String allotOrder, String materialNo, BigDecimal realAmount,
                                   Integer singelState, Integer totalState, String orgId, boolean updateReceipt)throws Exception{
        RegionAllotDetailVO detailVO = new RegionAllotDetailVO();
        detailVO.setAllotOrder(allotOrder);
        detailVO.setMaterialNo(materialNo);
        detailVO.setOrgId(orgId);
        List<RegionAllotDetailDO> list = regionAllotDetailMapper.list(detailVO);
        if(ListUtil.isNullOrEmpty(list)){
            return false;
        }
        RegionAllotDetailDO detailDO = list.get(0);
        BigDecimal nowAmount = realAmount.subtract(detailDO.getOutAmount()==null?BigDecimal.ZERO:detailDO.getOutAmount());
        detailDO.setOutAmount(realAmount);
        detailDO.setOutState(singelState);
        boolean success = regionAllotDetailMapper.updateByPrimaryKeySelective(detailDO)>0;
        if(success){
            RegionAllotVO inboundVO = new RegionAllotVO();
            inboundVO.setAllotOrder(allotOrder);
            inboundVO.setOrgId(orgId);
            List<RegionAllotDO> inboundList = regionAllotMapper.list(inboundVO);
            if(ListUtil.isNullOrEmpty(inboundList)) {
                return false;
            }
            RegionAllotDO inboundDO = inboundList.get(0);
            getOutState(allotOrder, totalState, orgId, inboundDO);

//            //调用crm接口，同步crm状态
//            if (companyUtil.isTJ(orgId)) {  //塔机用户才同步crm
//                Map resultMap = syncCrmByOutbound(allotOrder, materialNo, inboundDO);
//
//                boolean isSuccess = true;
//
//                //syncCrmFlag为null，为未同步
//                if (!StringUtil.isNotEmpty(inboundDO.getSyncCrmFlag())){
//                    inboundDO.setSyncCrmFlag("0");
//                }
//
//                //同步失败需要回写
//                if (resultMap.get("Flag") != null && resultMap.get("Flag").equals(false)){
//                    String msg = inboundDO.getSyncCrmMsg() == null ? "" : inboundDO.getSyncCrmMsg();
//                    msg += resultMap.get("Msg").toString() + ";";
//                    inboundDO.setSyncCrmFlag("2");
//                    inboundDO.setSyncCrmMsg(msg);
//                    isSuccess = false;
//                }
//
//                //本次成功，并且之前没有失败记录，则回写成功
//                if (isSuccess && !inboundDO.getSyncCrmFlag().equals("2")){
//                    inboundDO.setSyncCrmFlag("1");
//                    inboundDO.setSyncCrmMsg("操作成功");
//                }
//            }

            success = regionAllotMapper.updateByPrimaryKeySelective(inboundDO)>0;

            if(!success){
                return false;
            }

            if(updateReceipt){
                //更新发运交接单状态
                List<String> ids = deliveryReceiptLinkMapper.findReceiptIds(inboundDO.getId());
                if(!ListUtil.isNullOrEmpty(ids)){
                    List<DeliveryReceiptMaterialDO>  receiptMaterialDOList = deliveryReceiptMaterialMapper.listByIds(ids, materialNo);
                    if(!ListUtil.isNullOrEmpty(receiptMaterialDOList)){
                        for(DeliveryReceiptMaterialDO receiptMaterialDO : receiptMaterialDOList){
                            deliveryReceiptMaterialService.updateByOut(receiptMaterialDO, receiptMaterialDO.getOutQty().add(nowAmount));
                        }
                    }
                }
            }

        }
        return success;
    }

    private void getOutState(String allotOrder, Integer totalState, String orgId, RegionAllotDO inboundDO) {
        RegionAllotDetailVO regionAllotDetailVO = new RegionAllotDetailVO();
        regionAllotDetailVO.setAllotOrder(allotOrder);
        regionAllotDetailVO.setOrgId(orgId);
        boolean state = false;
        List<RegionAllotDetailDO> regionAllotDetailDOList = regionAllotDetailMapper.list(regionAllotDetailVO);
        for (RegionAllotDetailDO regionAllotDetailDO: regionAllotDetailDOList) {// 校验调拨详情中所有的出库状态是否全部==2
           Integer outState =  regionAllotDetailDO.getOutState();
           if (2 != outState){
               state = true;
               break;
           }
        }
        inboundDO.setOutState(totalState);
        if (!state){
            inboundDO.setOutState(2);
        }
    }

    public BigDecimal findSumAmountByOrders(List<String> allotOrderList) {
        return regionAllotDetailMapper.findSumAmountByOrders(allotOrderList);
    }

//    public void testCrmInterface(String materialNo,String allotOrder,String orgId) {
//
//        RegionAllotVO inboundVO = new RegionAllotVO();
//        inboundVO.setAllotOrder(allotOrder);
//        inboundVO.setOrgId(orgId);
//        List<RegionAllotDO> inboundList = regionAllotMapper.list(inboundVO);
//        RegionAllotDO inboundDO = inboundList.get(0);
//
//
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        RegionAllotCrmDO regionAllotCrmDO = new RegionAllotCrmDO();
//        regionAllotCrmDO.setCode(materialNo);
//        //regionAllotCrmDO.setReceiveQty(realAmount.toString());
//        regionAllotCrmDO.setReceiveTime(sdf.format(new Date()));
//        regionAllotCrmDO.setStatus(ConstantInfo.CRM_STATUS_RECEIVE);
//
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(1) && !ObjectUtils.isEmpty(inboundDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(inboundDO.getAllotPlanOrder());
//            BigDecimal amount = regionAllotDetailMapper.findSumAmountByPlanOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单入库,同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            Map resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单入库,同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//    }

//    public Map syncCrmByInbound(String allotOrder, String materialNo,RegionAllotDO inboundDO){
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        RegionAllotCrmDO regionAllotCrmDO = new RegionAllotCrmDO();
//        regionAllotCrmDO.setCode(materialNo);
//        //regionAllotCrmDO.setReceiveQty(realAmount.toString());
//        regionAllotCrmDO.setReceiveTime(sdf.format(new Date()));
//        regionAllotCrmDO.setStatus(ConstantInfo.CRM_STATUS_RECEIVE);
//
//        Map resultMap = new HashMap();
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(1) && !ObjectUtils.isEmpty(inboundDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(inboundDO.getAllotPlanOrder());
//            BigDecimal amount = regionAllotDetailMapper.findSumInAmountByPlanOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单入库,同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单入库,同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(2)) {
//            regionAllotCrmDO.setPmsCode(allotOrder);
//            BigDecimal amount = regionAllotDetailMapper.findSumInAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(),regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("list", regionAllotCrmDOList);
//            logger.info("区域调拨单入库,同步crm前移备件申请发货和签收信息,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncForwardPartsApply(paramMap);
//            logger.info("区域调拨单入库,同步crm前移备件申请发货和签收信息,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(5)){
//            regionAllotCrmDO.setPmsCode(inboundDO.getAllotOrder());
//            BigDecimal amount = regionAllotDetailMapper.findSumInAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单入库,三包备件-同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单入库,三包备件-同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        return resultMap;
//    }
//
//    public Map syncCrmByOutbound(String allotOrder, String materialNo,RegionAllotDO inboundDO){
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        RegionAllotCrmDO regionAllotCrmDO = new RegionAllotCrmDO();
//        regionAllotCrmDO.setCode(materialNo);
//        //regionAllotCrmDO.setReceiveQty(realAmount.toString());
//        regionAllotCrmDO.setReceiveTime(sdf.format(new Date()));
//        regionAllotCrmDO.setStatus(ConstantInfo.CRM_STATUS_DELEVERY);
//
//        Map resultMap = new HashMap();
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(1) && !ObjectUtils.isEmpty(inboundDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(inboundDO.getAllotPlanOrder());
//            BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByPlanOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单出库,同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单出库,同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(2)) {
//            regionAllotCrmDO.setPmsCode(allotOrder);
//            BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(),regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("list", regionAllotCrmDOList);
//            logger.info("区域调拨单出库,同步crm前移备件申请发货和签收信息,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncForwardPartsApply(paramMap);
//            logger.info("区域调拨单出库,同步crm前移备件申请发货和签收信息,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        if (!ObjectUtils.isEmpty(inboundDO.getAllotType()) && inboundDO.getAllotType().equals(5)) {
//            regionAllotCrmDO.setPmsCode(inboundDO.getAllotOrder());
//            BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty(amount.toString());
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单出库,三包备件-同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单出库,三包备件-同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        return resultMap;
//    }
//
//    public Map syncCrmBymanualFinishOut(String allotOrder, String materialNo,RegionAllotDO regionAllotDO){
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        RegionAllotCrmDO regionAllotCrmDO = new RegionAllotCrmDO();
//        regionAllotCrmDO.setCode(materialNo);
//        regionAllotCrmDO.setReceiveTime(sdf.format(new Date()));
//        regionAllotCrmDO.setStatus(ConstantInfo.CRM_STATUS_CANCLE);
//        Map resultMap = new HashMap();
//
//        if (!ObjectUtils.isEmpty(regionAllotDO.getAllotType()) && regionAllotDO.getAllotType().equals(1) && !ObjectUtils.isEmpty(regionAllotDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(regionAllotDO.getAllotPlanOrder());
//            //BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByPlanOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty("1");
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单结单,同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单结单,同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        if (!ObjectUtils.isEmpty(regionAllotDO.getAllotType()) && regionAllotDO.getAllotType().equals(2) && !ObjectUtils.isEmpty(regionAllotDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(allotOrder);
//            //BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty("1");
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("list", regionAllotCrmDOList);
//            logger.info("区域调拨单结单,同步crm前移备件申请发货和签收信息,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncForwardPartsApply(paramMap);
//            logger.info("区域调拨单结单,同步crm前移备件申请发货和签收信息,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//
//        if (!ObjectUtils.isEmpty(regionAllotDO.getAllotType()) && regionAllotDO.getAllotType().equals(5) && !ObjectUtils.isEmpty(regionAllotDO.getCrmOrder())) {
//            regionAllotCrmDO.setPmsCode(regionAllotDO.getAllotOrder());
//            //BigDecimal amount = regionAllotDetailMapper.findSumOutAmountByAllotOrderAndMaterialNo(regionAllotCrmDO.getPmsCode(), regionAllotCrmDO.getCode());
//            regionAllotCrmDO.setReceiveQty("1");
//            List<RegionAllotCrmDO> regionAllotCrmDOList = new ArrayList<>();
//            regionAllotCrmDOList.add(regionAllotCrmDO);
//            Map<String, List<RegionAllotCrmDO>> paramMap = new HashMap<>();
//            paramMap.put("DeliveryReceiptlist", regionAllotCrmDOList);
//            logger.info("区域调拨单结单,三包备件-同步crm发货签收,请求入参{}", JsonUtil.objectToString(paramMap));
//            resultMap = crmClient.syncPartsApply(paramMap);
//            logger.info("区域调拨单结单,三包备件-同步crm发货签收,返回结果{}", JsonUtil.objectToString(resultMap));
//        }
//
//        return resultMap;
//    }



}
